﻿namespace VueAdminService.VO
{
	/// <summary>
	/// 统一返回结果
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public class ResponseResult<T>
	{
		/// <summary>
		/// 状态码
		/// </summary>
		public ResponseCode Code { get; set; } = ResponseCode.Success;
		/// <summary>
		/// 返回内容
		/// </summary>
		public string? Msg { get; set; }
		/// <summary>
		/// 返回数据
		/// </summary>
		public T Data { get; set; }		
		/// <summary>
		/// 返回成功数据
		/// </summary>
		/// <param name="data"></param>
		/// <returns></returns>
		public static ResponseResult<T> SuccessResult(T data)
		{
			return new ResponseResult<T> { Code = ResponseCode.Success, Data = data };
		}
		/// <summary>
		/// 返回失败数据
		/// </summary>
		/// <param name="msg"></param>
		/// <param name="data"></param>
		/// <returns></returns>
		public static ResponseResult<T> FailedResult(string? msg,T data)
		{
			return new ResponseResult<T> { Code = ResponseCode.Failed, Msg = msg,Data=data };
		}
		/// <summary>
		/// 返回异常数据
		/// </summary>
		/// <param name="msg"></param>
		/// <param name="data"></param>
		/// <returns></returns>
		public static ResponseResult<T> ErrorResult(string? msg,T data)
		{
			return new ResponseResult<T> { Code = ResponseCode.Error, Msg = msg,Data=data };
		}
		/// <summary>
		/// 返回自定义数据
		/// </summary>
		/// <param name="code"></param>
		/// <param name="msg"></param>
		/// <param name="data"></param>
		/// <param name="rows"></param>
		/// <returns></returns>
		public static ResponseResult<T> Result(ResponseCode code, string? msg, T data)
		{
			return new ResponseResult<T> { Code = code, Msg = msg, Data = data};
		}
	}
	/// <summary>
	/// 统一返回结果
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public class ResponsePageResult<T>: ResponseResult<T>
	{		
		/// <summary>
		/// 总记录数,分页数据需要
		/// </summary>
		public int Rows { get; set; }
		/// <summary>
		/// 返回成功数据
		/// </summary>
		/// <param name="data"></param>
		/// <returns></returns>
		public static ResponsePageResult<T> SuccessPageResult(T data,int rows)
		{
			return new ResponsePageResult<T> { Code = ResponseCode.Success, Data = data,Rows=rows };
		}
		
		/// <summary>
		/// 返回自定义数据
		/// </summary>
		/// <param name="code"></param>
		/// <param name="msg"></param>
		/// <param name="data"></param>
		/// <param name="rows"></param>
		/// <returns></returns>
		public static ResponsePageResult<T> PageResult(ResponseCode code, string? msg, T data, int rows = 0)
		{
			return new ResponsePageResult<T> { Code = code, Msg = msg, Data = data, Rows = rows };
		}
	}
	/// <summary>
	/// 状态码
	/// </summary>
	public enum ResponseCode
	{
		/// <summary>
		/// 成功
		/// </summary>
		Success = 200,		
		/// <summary>
		/// 失败
		/// </summary>
		Failed = 299,
		/// <summary>
		/// 未授权
		/// </summary>
		Unauthorized = 401,
		/// <summary>
		/// 禁止访问
		/// </summary>
		Forbidden = 403,		
		/// <summary>
		/// 不被允许
		/// </summary>
		NotAcceptable=405,
		/// <summary>
		/// 错误
		/// </summary>
		Error = 500,
	}
}
